<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/14
 * Time: 16:23
 */
namespace app\api\controller;

use app\api\model\MtUserAmount;
use app\util\ReturnCode;

class Amount extends Base
{
    /**
     * 提现列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function amountList(){
        $userID = intval($this->request->param("userID"));
        $start = $this->request->get("start") ? strtotime($this->request->get("start")) : time();
        $begin_time = strtotime(date("Ym",$start));        //指定月份的开始时间戳
        $end_time = strtotime(date('Y-m-t',$start).' 23:59:59');
        $data = (new MtUserAmount())->where([["userID","=",$userID],["status","=","1"],[["cTime",">",$begin_time],['cTime',"<",$end_time]]])->order("cTime desc")->select(); // @todo status
        if(!$data){
            return $this->error(ReturnCode::DB_READ_ERROR,"查询失败");
        }
        $data = $data->toArray();
        foreach ($data as $k => $v){
            $data[$k]['cTime'] = date("Y-m-d H:i",$v['cTime'] );
            $data[$k]['mTime'] = date("Y-m-d H:i",$v['mTime'] );
        }
        return $this->success("查询成功",$data);
    }
}